#include "sIrrlichtEngine.h"
#include "sIrrlichtTexture.h"
#include "sIrrlichtFont.h"
#include "sIrrlichtDrawContext.h"

namespace sgui
{
namespace engine
{

    sTexture* sIrrlichtEngine::getTexture(const res::sTextureResource& res, const preset::sTexturePreset& preset)
    {
        return new sIrrlichtTexture(*this, res, preset);
    }
    
    sFont* sIrrlichtEngine::getFont(const res::sFontResource& res, const preset::sFontPreset& preset)
    {
        return new sIrrlichtFont(*this, res, preset);
    }
	
	sDrawContext* sIrrlichtEngine::getContext(const math::sRectf& rect) 
	{
		return new sIrrlichtDrawContext(*this, rect);
	}

    irr::video::IVideoDriver& sIrrlichtEngine::getDriver()
    {
        return *m_driver;
    }

    irr::IrrlichtDevice& sIrrlichtEngine::getDevice()
    {
        return *m_device;
    }

    irr::video::IVideoDriver& sIrrlichtEngine::getDriver() const
    {
        return *m_driver;
    }

    irr::IrrlichtDevice& sIrrlichtEngine::getDevice() const
    {
        return *m_device;
    }

    void sIrrlichtEngine::beginDraw() const
	{
		m_driver->beginScene(true, true, irr::video::SColor(255,0,0,0));
		m_driver->setRenderStates2DMode(true, true, true);

		glLoadIdentity();
	}

	void sIrrlichtEngine::endDraw() const
	{
		m_driver->setRenderStates3DMode();
		m_driver->endScene();
	}

	void sIrrlichtEngine::drawRect(const math::sRectf& rect, u32 color, bool fill) const
    {
		if (fill)
		{
			getDriver().draw2DRectangle(irr::video::SColor(color), toRect<s32>(rect.to<s32>()));
		}
		else
		{
			getDriver().draw2DRectangleOutline(toRect<s32>(rect.to<s32>()), irr::video::SColor(color));
		}
    }

    sIrrlichtEngine::sIrrlichtEngine(irr::video::IVideoDriver* driver, irr::IrrlichtDevice* device) :
        m_driver(driver), m_device(device)
    {
		
    }

};
};